﻿using Home.Domain.Entities.Mapping;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;

namespace Home.Domain.Entities
{
    //EF Code First需要创建的模型
    public class EFDbContext : DbContext
    {
        private const string ConnectionString = "name=db";

        public EFDbContext()
            : base(ConnectionString)
        {
            Configuration.ValidateOnSaveEnabled = false;//获取或设置一个值，该值指示是否跟踪的实体应验证自动调用 System.Data.Entity.DbContext.SaveChanges() 时。默认值为 true。
        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();//生成的表名不加s
            modelBuilder.Configurations.Add(new UserInfoMap());
            modelBuilder.Configurations.Add(new NewsMap());
            modelBuilder.Configurations.Add(new PNewsMap());
            //#region 不映射
            //modelBuilder.Ignore<Secondary.TPCUserInfo>(); 
            //#endregion
        }
        /// <summary>
        /// 公告
        /// </summary>
        public DbSet<Bulletin> Bulletins { get; set; }

        /// <summary>
        /// 用户
        /// </summary>
        public DbSet<UserInfo> UserInfos { get; set; }
        /// <summary>
        /// 新闻
        /// </summary>
        public DbSet<News> News { get; set; }
        /// <summary>
        /// 新闻分类
        /// </summary>
        public DbSet<PNews> PNews { get; set; }
        /// <summary>
        /// 文章
        /// </summary>
        public DbSet<Article> Articles { get; set; }
        /// <summary>
        /// 文章分类
        /// </summary>
        public DbSet<PArticle> PArticles { get; set; }
        /// <summary>
        /// 单一数据，根据名称判断
        /// </summary>
        public DbSet<SingleData> SingleDatas { get; set; }
        /// <summary>
        /// 留言板
        /// </summary>
        public DbSet<MessageBoard> MessageBoards { get; set; }
        /// <summary>
        /// 产品
        /// </summary>
        public DbSet<Product> Products { get; set; }
        /// <summary>
        /// 类别（大分类，如品牌，类别等）
        /// </summary>
        public DbSet<Classification> Classifications { get; set; }
        /// <summary>
        /// 分类（通用的）
        /// </summary>
        public DbSet<Category> Categorys { get; set; }
        /// <summary>
        /// 广告
        /// </summary>
        public DbSet<Advertising> Advertisings { get; set; }

        /// <summary>
        /// 成功案例
        /// </summary>
        public DbSet<Success> Successes { get; set; }
        /// <summary>
        ///成功案例分类
        /// </summary>
        public DbSet<LeiBie> LeiBies { get; set; }
        /// <summary>
        ///成功案例品牌
        /// </summary>
        public DbSet<Brand> Brands { get; set; }
    }
}
